<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-16 20:57:17
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-27 12:02:55
 * ------------------------------------------------ *
 * 导航管理                                         *
 * ------------------------------------------------ */
namespace Admin\Model;

class NavsModel extends CommonModel{
    protected $_auto = array ( 
         array('navType',0),
         array('navTitle'), 
         array('navUrl'),
         array('isShow',0),
         array('isOpen',0),
         array('navSort',0)
    );
	protected $_validate = array(     
		array('navType',array(0,1),'导航类型不对!',self::MODEL_BOTH,'in'),
		array('navTitle','1,50','导航名称长度不正确!',self::MODEL_BOTH,'length'),
		array('navUrl','1,100','导航链接长度不正确!',self::MODEL_BOTH,'length'),
		array('isShow',array(0,1),'是否显示类型不对!',self::MODEL_BOTH,'in'),
		array('isOpen',array(0,1),'是否打开新窗口类型不对!',self::MODEL_BOTH,'in'),
	);
	

// 新增

	 public function addNavs(){
	 	$m = M('navs');
		$data = $m->create();
		if(!$data){
			$rd['msg'] = $m->getError();
			return false;
		}
		$data['createTime'] = date('Y-m-d H:i:s');
		$rs = $m->add($data);
		if(false !== $rs){
			return true;
		}
		return false;
	 } 
 
// 修改

	 public function editNavs(){
	 	$m = M('navs');
	    $data = $m->create();
		if(!$data){
			$rd['msg'] = $m->getError();
			return flase;
		}
		$rs = $m->where("id=".(int)I('id',0))->save($data);
		if(false !== $rs){
			return true;

		}
		return false;
	 } 

// 获取指定对象

     public function getNavs(){
	 	$m = M('navs');
		return $m->where("id=".I('id'))->find();
	 }



// 删除

	 public function delNavs(){
	    $m = M('navs');
	    $rs = $m->delete((int)I('id'));
		if(false !== $rs){
		   return true;
		}
		return false;
	 }
	 
 
// 是否显示/隐藏

	 public function isShow(){
	 	
	 	$m = M('navs');
	 	$m->isShow = (I('isShow')==1)?1:0;
	 	$rs = $m->where("id = ".(int)I('id',0))->save();
	    if(false !== $rs){
			return true;
		}
	 	return false;
	 }
	 
 
 // 是否新窗口打开

	 public function isOpen(){
	 	
	 	$m = M('navs');
	 	$m->isOpen = (I('isOpen')==1)?1:0;
	 	$rs = $m->where("id = ".(int)I('id',0))->save();
	    if(false !== $rs){
			return true;
		}
	 	return flase;
	 }
}